package com.zijie.hosptal.controller;

import com.zijie.hosptal.common.Result;
import com.zijie.hosptal.util.CaptchaUtil;
import com.zijie.hosptal.util.ThreadLocalUtil;
import jakarta.servlet.http.HttpSession;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@RestController
@RequestMapping("/login")
public class LoginController {


    @GetMapping("/captcha")
    public Result<?> captcha(HttpSession session) {
        // 生成一个随机字符串
        String captcha = CaptchaUtil.randomCode(3);
//        ThreadLocalUtil.set("captcha", captcha);
//        System.out.println("captcha: " + ThreadLocalUtil.get("captcha"));
        session.setAttribute("captcha", captcha);
        // 生成Base64格式的图片
        String img = CaptchaUtil.createBase64(captcha);
        // 生成 key, 10分钟有效
//        String key = JWTUtil.createJWT(captcha, 10*60*1000L);
        return Result.success(img);
    }
}
